
#include "event.h"
#include "node.h"
#include "simulator.h"
#include "undertopomgr.h"
#include "eventdefs.h"
#include "peerloger.h"

void Node::onEvent( Event *event )
{
	switch( event->getType() ){
		case Event::RECV_PACK:
			onReceived( static_cast<RecvPackEvent*>(event)->getPacket() );
			break;
		default:
			assert(false);
			break;
	}
}

void Node::onTimer( Timer *timer )
{
}

bool Node::send( node_id_t dst_id, Packet *packet )
{
	assert( isOnline() );
	PeerLoger::instance().logTrans( 0, "%d send packet to %d", 
			getNodeID(), dst_id );
	packet->incHops();
	return UnderTopoMgr::instance().send( getNodeID(), dst_id, packet );
}

void Node::onJoining()
{
	setOnline( true );
}

void Node::onDeparture()
{
	setOnline( false );
}
